<%--
  Created by IntelliJ IDEA.
  User: apple
  Date: 2020/4/21
  Time: 11:19 上午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>签到</title>
    <link rel="stylesheet" href="static/css/bootstrap.min.css">
    <link rel="stylesheet" href="static/css/style.css">
    <link rel="stylesheet" href="static/css/qiandao_style.css">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-xs-12 clearPadding">
            <!--<div class=""><img src="images/qdBanner.jpg" class="img-responsive"></div>-->
<input type="hidden" id="uid" value="${uid}">
            <div class="calendar">
                <div class="calenbox">
                    <div id="calendar"></div>
                </div>
                <div class="text-center">
                    <button class="btn btn-qiandao" onclick="signIn()">马上签到</button>
                </div>
            </div>
            <div class="padding10">
                <div class="font16 pb10 borderb"><strong>连续签到礼包</strong></div>
                <div class="libaolist">
                    <c:forEach items="${activityies}" var="item">
                    <div class="clearfix borderb ptb10">
                        <div class="col-xs-9 clearPadding">
                            <div class="media">
                                <a class="media-left pt3" href="javascript:void(0);">
                                    <img src="static/picture/dou.png" style="width:30px;height:30px;">
                                </a>
                                <div class="media-body">
                                    <div class="">${item.count}天礼包（${item.money}积分）</div>
                                    <div class="text-muted font12">连续签到${item.count}天即可领取</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-3 clearPadding text-right pt2">
                            <button id="sign${item.count}" class="btn btn-disable " onclick="linqu(${item.id})">领取</button>
                        </div>
                    </div>
                    </c:forEach>
                    </div>
            </div>


        </div>
    </div>
</div>
<div style="display: none">
    <input type="hidden" id="daycount" value=" <c:forEach items="${activityies}" var="activity">
                ${activity.count},
                </c:forEach>">
</div>
<div class="maskbox"></div>
<div class="qdbox">
    <div class="text-center text-green font18"><strong>签到成功！</strong></div>
    <div class="text-center pt10">您已经连续签到&nbsp;<span class="text-green">10</span>&nbsp;天</div>
    <div class="text-center ptb15"><img src="static/picture/gift.png" style="width:125px;margin-left:20px;"></div>
    <div class="text-center"><button class="btn btn-lottery">收到</button></div>
</div>
<script src="static/js/jquery-1.10.2.min.js"></script>
<script src="static/js/calendar.js"></script>
<script>
    function  linqu(actid) {
        var uid = $("#uid").val();
        $.ajax({
            url: "/lqjifen",
            type: "post",
            data: {uid: uid, actid: actid},
            success: function (data) {
                if (data == (-1)) {
                    alert("今天已签到")
                } else {
                    alert("恭喜你签到成功")
                    var btn = "#sign" + actid;
                    $(btn).removeClass();
                    $(btn).addClass("btn btn-disable");
                    $(btn).attr("disabled", true);
                    if (item <= count) {
                        $(btn).removeClass();
                        $(btn).addClass("btn btn-lingqu");
                        $(btn).attr("disabled", false);
                    }
                }

            }
        })
    }

        function signIn() {
            /* $(".maskbox").fadeIn();
             $(".qdbox").fadeIn();
             $(".maskbox").height($(document).height());
     */
            var uid = $("#uid").val();
            $.ajax({
                url: "/sign",
                type: "post",
                data: {uid: uid},
                success: function (data) {
                    if (data == (-1)) {
                        alert("今天已签到")
                    } else {
                        alert("恭喜你签到成功")
                    }

                }
            })
        }

        $(".maskbox").click(function () {
            $(".maskbox").fadeOut();
            $(".qdbox").fadeOut();
        });
        $(function () {
            var uid = $("#uid").val();
            //var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}];
            //calUtil.init(signList);
            var signList = [];
            $.ajax({
                url: "/dayList",
                type: "post",
                data: {uid: uid},
                success: function (data) {
                    if (data.status == 200) {
                        var list = data.data
                        for (var i = 0; i < list.length; i++) {
                            var obj = {"signDay": list[i].day};
                            signList.push(obj);
                            calUtil.init(signList);
                        }
                    } else {
                        alert("初始化数据失败")
                    }
                }
            })
           // var arr=$("#daycount").val();

            $.ajax({
                url: "/dayCount",
                type: "post",
                data: {uid: uid},
                success: function (data) {
                    if (data.status == 200) {
                        var count = data.data;
                        var arr = [
                            <c:forEach items="${activityies}" var="activity">
                            ${activity.count},
                            </c:forEach>

                        ];
                        arr.forEach(function (item, index, arr) {
                            var btn = "#sign" + item;
                            $(btn).removeClass();
                            $(btn).addClass("btn btn-disable");
                            $(btn).attr("disabled", true);
                            if (item<=count) {
                                $(btn).removeClass();
                                $(btn).addClass("btn btn-lingqu");
                                $(btn).attr("disabled", false);
                            }
                        })
                    } else {
                        alert("初始化数据失败");
                    }
                }
            })
            $.ajax({
                url: "/actlog",
                type: "post",
                data: {uid: uid},
                success: function (data) {
                    if (data.status == 200) {
                        var list = data.data;
                        list.forEach(function (item, index, arr) {
                            var btn = "#sign" + item.count;
                            $(btn).removeClass();
                            $(btn).addClass("btn btn-disable");
                            $(btn).attr("disabled", true);


                        })

                    } else {
                        alert("初始化数据失败");
                    }
                }
            })
        });

</script>
</body>
</html>

